
package entity;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for Users complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="Users">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="UserID" type="{http://xml.netbeans.org/schema/Users}user"/>
 *         &lt;element name="Password" type="{http://xml.netbeans.org/schema/Users}user"/>
 *         &lt;element name="UserRole" type="{http://xml.netbeans.org/schema/Users}role"/>
 *         &lt;element name="Birthday" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="UserAddress" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="Phone" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Users", propOrder = {
    "userID",
    "password",
    "userRole",
    "birthday",
    "userAddress",
    "phone"
})
public class Users {

    @XmlElement(name = "UserID", required = true)
    protected String userID;
    @XmlElement(name = "Password", required = true)
    protected String password;
    @XmlElement(name = "UserRole", required = true)
    protected String userRole;
    @XmlElement(name = "Birthday", required = true, nillable = true)
    protected String birthday;
    @XmlElement(name = "UserAddress", required = true, nillable = true)
    protected String userAddress;
    @XmlElement(name = "Phone", required = true, nillable = true)
    protected String phone;

    public Users() {
    }

    public Users(String userID, String password, String userRole, String birthday, String userAddress, String phone) {
        this.userID = userID;
        this.password = password;
        this.userRole = userRole;
        this.birthday = birthday;
        this.userAddress = userAddress;
        this.phone = phone;
    }

    /**
     * Gets the value of the userID property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getUserID() {
        return userID;
    }

    /**
     * Sets the value of the userID property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setUserID(String value) {
        this.userID = value;
    }

    /**
     * Gets the value of the password property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getPassword() {
        return password;
    }

    /**
     * Sets the value of the password property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setPassword(String value) {
        this.password = value;
    }

    /**
     * Gets the value of the userRole property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getUserRole() {
        return userRole;
    }

    /**
     * Sets the value of the userRole property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setUserRole(String value) {
        this.userRole = value;
    }

    /**
     * Gets the value of the birthday property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getBirthday() {
        return birthday;
    }

    /**
     * Sets the value of the birthday property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setBirthday(String value) {
        this.birthday = value;
    }

    /**
     * Gets the value of the userAddress property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getUserAddress() {
        return userAddress;
    }

    /**
     * Sets the value of the userAddress property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setUserAddress(String value) {
        this.userAddress = value;
    }

    /**
     * Gets the value of the phone property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getPhone() {
        return phone;
    }

    /**
     * Sets the value of the phone property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setPhone(String value) {
        this.phone = value;
    }

        public Users login(String username, String password) {
        try {
            Users user = new Users();
            ConnectDB con = new ConnectDB();
            Connection connect = con.getCon();
            Statement stm = connect.createStatement();

            String query = "select * from Users where UserID='" + username
                    + "' and UserPassword='" + password + "'";
            ResultSet rs = stm.executeQuery(query);
            while (rs.next()) {
                String userid = rs.getString(1);
                String pass = rs.getString(2);
                String role = rs.getString(3);
                String dob = rs.getString(4);
                String address = rs.getString(5);
                String phonenumber = rs.getString(6);
                user = new Users(userid,pass,role,dob,address,phonenumber);
            }
            return user;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
